package org.eduapp.trains.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.eduapp.trains.Constants;

public class UtilsMSDoc {
	
	public static void save() {
		String content = "";
		try {
			InputStream inputStream = new FileInputStream(UtilsResources.getWebRootPath() + Constants.DefaultFileUploadDir + "/sms/" + "1" + ".txt");
			byte[] by = new byte[1024];
			int byteread = 0;
            // 读入多个字节到字节数组中，byteread为一次读入的字节数
            while ((byteread = inputStream.read(by)) != -1) {
                System.out.write(by, 0, byteread);
                content += new String(by, "UTF-8");
               
            }

		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String name = "0610d_James";
		 File file = new File(UtilsResources.getWebRootPath() + Constants.DefaultFileUploadDir + "/sms/" + name + ".doc");
	        OutputStream outputStream;
			try {
				outputStream = new FileOutputStream(file);
				outputStream.write(content.replaceFirst("<table", "<table style='font-size:8pt;' ").getBytes("UTF-8"));
		        outputStream.close();
			}catch (Exception e) {
				// TODO: handle exception
			}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		UtilsMSDoc.save();
	}

}
